package controlleur;

import java.util.ArrayList;

import json.JsonParserSuccursale;
import modele.DAO.DaoSuccursale;
import data.Succursale;

public class SuccursaleControlleur extends Controlleur{
	
	private DaoSuccursale daoSuccursale;

	public SuccursaleControlleur()
	{
		daoSuccursale = new DaoSuccursale();
	}
	
	public String getAllSuccFromDet(int idDetaillant)
	{
		JsonParserSuccursale jpSucc = new JsonParserSuccursale();
		ArrayList<Succursale> succursales = daoSuccursale.findFromDet(idDetaillant);	
		
		String allSuccDet = "";
		
		for(Succursale s:succursales)			
			allSuccDet+=jpSucc.jsonCreate(s)+"\n";
		return allSuccDet;
		
	}
	
	public String getSucc(int idSuccur)
	{
		JsonParserSuccursale jpSucc = new JsonParserSuccursale();
		Succursale s = daoSuccursale.find(idSuccur);			
		return jpSucc.jsonCreate(s)+"\n";
	}

	public void addSucc(String nom, String adresse, String codePostal, String description,int idDetaillant) 
	{
		Succursale s = new Succursale();
		s.setNom(nom);
		s.setAdresse(adresse);
		s.setCodePostal(codePostal);
		s.setDescription(description);
		s.setIdDetaillant(idDetaillant);
		
		daoSuccursale.create(s);
	}
	
	public void delSucc(int idSuccur)
	{
		Succursale s = new Succursale();
		s.setId(idSuccur);
		daoSuccursale.delete(s);
	}

	public void updSucc(int id, String nom, String adresse, String codePostal, int longitude, int latitude, String description) 
	{
		Succursale s = new Succursale();
		s.setNom(nom);
		s.setAdresse(adresse);
		s.setCodePostal(codePostal);
		s.setLongitude(longitude);
		s.setLatitude(latitude);
		s.setDescription(description);
		s.setId(id);
		
		daoSuccursale.update(s);		
	}

}
